<?php
class GestionRole {
    private $conBDD;
    public function __construct($conBDD){
        $this->conBDD=$conBDD;
    }
    public function getListeRole($WHERE=NULL){
        $query="";
        $query.="SELECT * FROM scrum_role";
        if($WHERE!=NULL){
            $query.=" WHERE ".  implode(" AND ", $WHERE)." ";
        }
        $res=$this->conBDD->query($query);
        $tabRole=array();
        while($row = mysql_fetch_array($res)){
            $role=new Role();
            $role->setIdRole($row["idrole"]);
            $role->setIntitule($row["intitule"]);
            $role->setRole($row["role"]);
            $role->setSchema($row["schema"]);
            $role->setTags($row["tags"]);
            $tabRole[$row["idrole"]]=$role;
        }
        return $tabRole;
    }
    public function ajoutRole(array $SET){
        $query="";
        $query.="INSERT INTO scrum_role ";
        $query.="SET ";
        $query.=implode(", ", $SET);
        $res=$this->conBDD->exec($query);
        return $res;
    }
    public function getAllTags($term){
        $query="";
        $query.="SELECT tags FROM scrum_role";
        $query.=" WHERE tags LIKE '%".$term."%' ";
        $res=$this->conBDD->query($query);
        $tabTags=array();
        while($row = @mysql_fetch_array($res)){
            $tmp=array();
            $tmp=explode(",",$row["tags"]);
            foreach($tmp as $val){
                if(@preg_match("/".$term."/i", $val)) $tabTags[utf8_encode($val)]=trim(utf8_encode($val));
            }
            
        }
        return $tabTags;
    }
    public function getTabHtml($tabRole){
        $html="";
        if(sizeof($tabRole)>0){
            foreach($tabRole as $id=>$rol){
                $html.= "<div>";
                    $html.= "<p class='justified'>";
                        $html.= nl2br(utf8_encode($rol->getRole()) );
                    $html.= "</p>";
                $html.= "</div>";
            }
        }
        else{
            if(isset($_GET['search_titre'])){
                $html.= "Pas de résultat(s) pour '".$_GET['search_titre']."'";
            }
            else{
                $html.= "Rien";
            }
        }
        return $html;
    }
}
?>
